package com.lwc.cfdns.controller.admin.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lwc.cfdns.constants.ConstantsUrl;
import com.lwc.cfdns.pojo.bo.system.DictDataBO;
import com.lwc.cfdns.pojo.dto.ValidGroup;
import com.lwc.cfdns.pojo.dto.system.DictDataDTO;
import com.lwc.cfdns.pojo.entity.SystemDictData;
import com.lwc.cfdns.pojo.vo.system.DictDataVO;
import com.lwc.cfdns.service.impl.SystemDictDataServiceImpl;
import com.lwc.cfdns.service.impl.SystemDictServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * 字典数据
 *
 * @author luwc
 * @title DictDataController
 * @description
 * @time 2023/5/29 12:01:23
 * @version: 1.0
 */
@RestController
@RequestMapping(ConstantsUrl.ADMIN + "/system")
public class DictDataController {
    @Autowired
    private SystemDictDataServiceImpl systemDictDataService;
    @Autowired
    private SystemDictServiceImpl systemDictService;

    /**
     * 创建
     *
     * @param dictDataDTO
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/29 12:05:43
     */
    @PostMapping("/dict/data")
    public Map<String, Object> create(@Validated(ValidGroup.Create.class) @RequestBody DictDataDTO dictDataDTO) {
        return systemDictDataService.create(dictDataDTO);
    }

    /**
     * 修改
     *
     * @param dictDataDTO
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/29 12:07:09
     */
    @PutMapping("/dict/data")
    public Map<String, Object> update(@Validated(ValidGroup.Update.class) @RequestBody DictDataDTO dictDataDTO) {
        return systemDictDataService.update(dictDataDTO);
    }

    /**
     * 详情
     *
     * @param id
     * @return DictDataVO
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/29 12:10:12
     */
    @GetMapping("/dict/data/{id}")
    public DictDataVO view(@PathVariable("id") @NotNull(message = "ID不能为空!") Long id) {
        return systemDictDataService.view(id);
    }

    /**
     * 删除（支持批量）
     *
     * @param ids
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/29 12:11:12
     */
    @DeleteMapping("/dict/data/{id}")
    public Map<String, Object> delete(@PathVariable("id") @NotNull(message = "ID不能为空") String ids) {
        return systemDictDataService.delete(ids);
    }

    /**
     * 列表
     *
     * @param dictDataBO
     * @return IPage<SystemDictData>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/29 12:33:23
     */
    @GetMapping("/dict/data")
    public IPage<SystemDictData> lists(DictDataBO dictDataBO) {
        return systemDictDataService.lists(dictDataBO);
    }

    /**
     * 查询字典缓存
     *
     * @param marks
     * @return IPage<SystemDictData>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/29 15:50:42
     */
    @GetMapping("/dict/data/cacheMarks/{marks}")
    public List<DictDataVO> cacheOfMarks(@PathVariable("marks") @NotBlank(message = "字典标识不能为空") String marks) {
        return systemDictDataService.cacheOfMarks(marks);
    }
}
